
    <title>新增运单</title>
    <style type="text/css">
        .proposal-box {
            position: absolute;
            height: auto;
            border-left: 1px solid rgba(0, 0, 0, 0.11);
            border-right: 1px solid rgba(0, 0, 0, 0.11);
            left: 0px;
        }
        .proposal-list {
            list-style: none;
            box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.44);
            -webkit-margin-before: 0em;
            -webkit-margin-after: 0em;
            -webkit-margin-start: 0px;
            -webkit-margin-end: 0px;
            -webkit-padding-start: 0px;
        }
        .layui-form-select .layui-input {
            padding-right: 0px;
            cursor: pointer;
        }
    </style>
</head>
</head>
<body>


<!-------------------------------------------运单的信息------------------------------>
<div class="layui-fluid" style="padding: 15px">
    <div class="layui-card" style="padding-top: 10px">
        <div class="layui-col-md12">
            <div class="layui-card" style="padding: 10px">

                <form class="layui-form"  method="post">
                    <div class="layui-row" style="width:100%;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">托运单号</label>
                                <div class="layui-input-inline">
                                    <input type="tel" id="waybill_id" name="waybillId" required autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">出发站</label>
                                <div class="layui-input-inline">
                                    <select name="email" id="email" lay-verify="required">
                                        <option value="">请选择出发站</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">到达城市</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="arrivalCity "id="arrivalCity"  autocomplete="on" class="layui-input" lay-verify="required" >
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">到达分站</label>
                                <div class="layui-input-inline required">
                                    <select name="substationunit" id="substationUnit" lay-verify="required">
                                        <option value="">请选择出发站</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row" style="padding-top: 10px;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">托运日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="consigndate" id="date1" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr/>

                    <!-------------------------------------------收发人的信息------------------------------>
                    <div class="layui-row" style="width:100%;">
                        <div class="layui-col-md12">
                            <div style="width:100%;">
                                <p  style="padding-left: 20px;">
                                    <font color="#FF0000">收发信息</font>
                                </p>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row" style="width:100%;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">发货单位</label>
                                <div class="layui-input-inline selectTitleDiv" id="search-form0">
                                    <input type="tel" name="forwardingunit" required id="textValue0" autocomplete="off" class="layui-input textValue" lay-verify="required">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">发货人</label>
                                <div class="layui-input-inline selectTitleDiv" id="search-form1">
                                    <input type="tel" name="clientname" required  id="textValue1" autocomplete="off" class="layui-input textValue" lay-verify="required">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">联系电话</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="phone"  id="phone" required autocomplete="off" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">备用电话</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="alternatephone" required  id="alternatephone"  autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row" style="width:100%; padding-top: 10px;">
                        <div class="layui-col-md9">
                            <div class="layui-form-item" style="margin-bottom: 5px">
                                <label class="layui-form-label">请选择地区</label>
                                <div class="layui-inline">
                                    <select name="province" id="province1" class="province"  lay-search lay-filter="province">
                                        <option value="">省份</option>
                                    </select>
                                </div>
                                <div class="layui-inline">
                                    <select name="city" id="city1"     class="city"  lay-search lay-filter="city">
                                        <option value="">地级市</option>
                                    </select>
                                </div>
                                <div class="layui-inline">
                                    <select name="district" id="district1" lay-filter="district" class="district"  lay-search>
                                        <option value="">县/区</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label"  style="padding-left: 0px;width: 95px">发货详细地址</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="detailedAddress1"  required id="detailedAddress1" autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-------------------------------------------收货人的信息------------------------------>
                    <div class="layui-row" style="width:100%; ">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">收货单位</label>
                                <div class="layui-input-inline selectTitleDiv" id="search-form2">
                                    <input type="tel" name="forwardingunit"   id="textValue2" autocomplete="off" class="layui-input textValue required">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">收货人</label>
                                <div class="layui-input-inline  selectTitleDiv" id="search-form3">
                                    <input type="tel" name="clientname"  id="textValue3"   autocomplete="off" class="layui-input textValue">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">联系电话</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="phone" id="phone1"   autocomplete="off" class="layui-input textValue" >
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">备用电话</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="alternatephone" id="alternatephone1"   autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row" style="width:100%; padding-top: 10px;">
                        <div class="layui-col-md9">
                            <div class="layui-form-item"  style="margin-bottom: 5px">
                                <label class="layui-form-label">请选择地区</label>
                                <div class="layui-inline">
                                    <select name="province" id="province" class="province"  lay-search lay-filter="province">
                                        <option value="">省份</option>
                                    </select>
                                </div>
                                <div class="layui-inline">
                                    <select name="city" id="city"     class="city"  lay-search lay-filter="city">
                                        <option value="">地级市</option>
                                    </select>
                                </div>
                                <div class="layui-inline">
                                    <select name="district" id="district"   lay-filter="district1"  class="district"  lay-search >
                                        <option value="">县/区</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label" style="padding-left: 0px;width: 95px">收货详细地址</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="detailedAddress" id="detailedAddress" required autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr/>

                    <!--                        ---------------------------- 基本信息-------------------------                          -->
                    <div class="layui-row" style="width:100%;">
                        <div class="layui-col-md12">
                            <div style="width:100%;">
                                <p  style="padding-left: 20px;">
                                    <font color="#FF0000">基本信息</font>
                                </p>
                            </div>
                        </div>
                    </div>


                    <div class="layui-row" style="width:100%;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">送货方式</label>
                                <div class="layui-input-inline">
                                    <select name="modetransport" id="modetransport" lay-verify="required">
                                        <option value="自提">自提</option>
                                        <option value="等通知提">等通知提</option>
                                        <option value="等通知送">等通知送</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">运输类型</label>
                                <div class="layui-input-inline">
                                    <select name="typetransportation" id="typetransportation" lay-verify="required">
                                        <option value="普通运输">普通运输</option>
                                        <option value="加急卡班">加急卡班</option>
                                        <option value="整车运输">整车运输</option>
                                        <option value="航空运输">航空运输</option>
                                        <option value="铁路运输">铁路运输</option>
                                        <option value="冷链运输">冷链运输</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">承诺日期</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="datearrival" id="date" required lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">订单编号</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="dindanbianhao" id="ordernumber"  required autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                    </div>
                    <hr/>
                    <div class="layui-row" style="width:100%;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">货物名称</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="descriptiongoods" id="descriptiongoods" required  placeholder="货物名称" autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">包装</label>
                                <div class="layui-input-inline">
                                    <select id="packaging" lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="纸箱">纸箱</option>
                                        <option value="木箱">木箱</option>
                                        <option value="托盘">托盘</option>
                                        <option value="桶装">桶装</option>
                                        <option value="裸装">裸装</option>
                                        <option value="袋装">袋装</option>
                                        <option value="缠绕膜">缠绕膜</option>
                                        <option value="其他">其他</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">总数量</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="quantity" id="quantity" required   autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">单个重量</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="weight" id="weight" required   autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row" style="width:100%; padding-top: 10px;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">单个体积</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="volume" id="volume"  required  autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">单价</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="unitprice" id="unitprice" required   autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">计费方式</label>
                                <div class="layui-input-inline">
                                    <select id="tollcollectionmanner" lay-filter="xcl">
                                        <option value="0">请选择</option>
                                        <option value="重量">重量</option>
                                        <option value="体积">体积</option>
                                        <option value="件数">件数</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">基本运费</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="basic" id="basic" required   autocomplete="on" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row" style="width:100%; padding-top: 10px;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">提货费</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="picupcharge" id="picupcharge" autocomplete="on"  class="layui-input  aggregateamount">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">送货费</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="deliveryfee"  id="deliveryfee"  autocomplete="on" class="layui-input  aggregateamount">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">货物价值</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="cargovalue" id="cargovalue"    autocomplete="on" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">保费</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="premium" id="premium"  autocomplete="on" class="layui-input  aggregateamount">
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row" style="width:100%; padding-top: 10px;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">卸货费</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="unloadfee" id="unloadfee"  autocomplete="on" class="layui-input  aggregateamount">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">其他费用</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="elsefee" id="elsefee"   autocomplete="on" class="layui-input  aggregateamount">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">返利代收</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="rebate" id="rebate" autocomplete="on" class="layui-input  aggregateamount">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">付款方式</label>
                                <div class="layui-input-inline">
                                    <select id="paymentmethod">
                                        <option value="">请选择</option>
                                        <option value="现金">现金</option>
                                        <option value="微信">微信</option>
                                        <option value="支付宝">支付宝</option>
                                        <option value="刷卡">刷卡</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-row" style="width:100%; padding-top: 10px;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">应收总额</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="aggregateamount" id="aggregateamount"  autocomplete="on" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">现收</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="nowclosed" id="nowclosed"  autocomplete="on" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">回付月结</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="password" id="password"    autocomplete="on" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">到付</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="freightcollect"  id="freightcollect" autocomplete="on" class="layui-input">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row" style="width:100%; padding-top: 10px;">
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">回单</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="password" id="passwordS" autocomplete="on" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline" style="text-align: center">
                                <button type="button" id="addPrice" class="layui-btn"  >填入费用</button>
                                <button type="button" id="price" class="layui-btn"  >修改费率计算规则</button>
                            </div>
                        </div>
                    </div>
                    <hr/>
                    <div class="layui-row" style="width:100%; padding-top: 10px;">
                        <div class="layui-col-md3">
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">备注</label>
                                <div class="layui-input-block">
                                    <textarea name="remark" id="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">业务员</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="password" id="username"  autocomplete="on" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3">
                            <div class="layui-inline">
                                <label class="layui-form-label">开单员</label>
                                <div class="layui-input-inline">
                                    <input type="tel" name="password" id="username1" autocomplete="on"  disabled="disabled" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md3" style="padding-top: 10px;">
                            <div class="layui-form-item">
                                <button type="button" class="layui-btn" lay-submit="" lay-filter="demo1">提交订单</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 三级联动 -->

<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate','jquery'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        var $ = layui.jquery;
        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });
        //显示网址
        var locationi=location.href;
        //根据下标截取字符串获得id
        var id=locationi.substring(locationi.indexOf("=")+1);

        //zzg补充代码发
        //1.0绑定离焦事件
        $("#arrivalCity").on("blur", function(){
            $("#substationUnit option").each(function(){  //遍历所有option
                var txt = $(this).text();   //获取option值
                if(txt==($("#arrivalCity").val()+"站")||txt==($("#arrivalCity").val()+"省")){
                    $("#substationUnit option[value='"+$(this).val()+"']").attr("selected","selected");
                }
            })
            form.render("select");
        });
        //值改变
        $("#price").on("click",function () {
            layer.open({
                type: 2,
                title: '修改菜单数据',
                shadeClose: true,
                shade: 0.8,
                area: ['800px', '90%'],
                content: '../src/views/waybillManagement/iframe/Price.html' //iframe的url
            });
        })
        $("#addPrice").on("click",function () {
            $.post("../../PriceId",
                function(data){
                    $("#picupcharge").val(parseFloat($("#basic").val()*data.pickupcharge).toFixed(2))//提货费
                    $("#deliveryfee").val(parseFloat($("#basic").val()*data.deliveryexpense).toFixed(2))//送货费
                    $("#unloadfee").val(parseFloat($("#basic").val()*data.landingcharges).toFixed(2))//卸货费
                    $("#premium").val(parseFloat($("#cargovalue").val()*data.premium).toFixed(2))//保费
                    $("#elsefee").val(0)//其它
                    $("#rebate").val(0)//返利代收
                    //存储总值
                    var a=1;
                    $(".aggregateamount").each(function(){
                        //判断是否为null和kong
                        if($(this).val()!=""&&$(this).val()!=null){
                            a+=parseInt($(this).val());
                        }
                    })
                    $('#aggregateamount').val(parseInt($('#basic').val())+parseInt(a)-1);

                    $("#nowclosed").val(0)//现收
                    $("#password").val(0)//回付月结
                    $("#freightcollect").val(0)//到付
                    $("#passwordS").val(0)//回单
                    $("#paymentmethod option[value='现金']").attr("selected","selected");//付款方式
                    form.render("select");
                }, "json");
        })
        function dizhi() {
            $.ajax({
                url: "../../getAllSubstation",
                type: "post",
                dataType: "json",
                success: function (data) {
                    //动态添加下拉框
                    for (var i = 0; i < data.length; i++) {
                        $("#substationUnit").append("<option value='" + data[i].subId + "'>" + data[i].subName + "</option>");
                    }
                    for (var i = 0; i < data.length; i++) {
                        $("#email").append("<option value='" + data[i].subId + "'>" + data[i].subName + "</option>");
                    }
                    //刷新
                    form.render('select');
                }
            });
            //收货详细地址
            var she=$("#detailedAddress").val().substring(0,2);
            var shi=$("#detailedAddress").val().substring(3,5);
            //发货文字
            var she1=$("#detailedAddress1").val().substring(0,2);
            var shi1=$("#detailedAddress1").val().substring(3,5);
            //出发站
            //发货地址
            var options=$("#email option:selected").text().substring(0,2);
            //收货地址
            var options1=$("#substationUnit option:selected").text().substring(0,2);
            //判断收货地址是否是与分站匹配
            if (options1!=she){
                $("#substationUnit option").each(function(){  //遍历所有option 出发站
                    var txt = $(this).text().substring(0,2);   //获取option值
                    if(txt==she){
                        queren($(this).val());
                        $("#arrivalCity").val(she)
                        return;
                    }
                    return;
                })
            }else if (options1!=shi&&options1!=she){
                $("#substationUnit option").each(function(){  //遍历所有option 出发站
                    var txt = $(this).text().substring(0,2);   //获取option值
                    if(txt==shi){
                        queren($(this).val());
                        $("#arrivalCity").val(shi);
                        return;
                    }
                    return;
                })
            }
            //判断发货地址是否是与分站匹配
            if (options!=she1){
                $("#email option").each(function(){  //遍历所有option 出发站
                    var txt = $(this).text().substring(0,2);;   //获取option值
                    if(txt==she1||txt==shi1){
                        queren2($(this).val());
                        return;
                    }
                    return;
                })
            }else if (options!=she1&&options!=shi1){
                $("#email option").each(function(){  //遍历所有option 出发站
                    var txt = $(this).text().substring(0,2);;   //获取option值
                    if(txt==she1||txt==shi1){
                        queren2($(this).val());
                        return;
                    }
                    return;
                })
            }
            form.render("select");
        }
        function queren(value){
            var result= confirm("系统匹配到与您收货地址更合适的分站是否要切换");
            if( result== true ){
                $("#substationUnit option[value='"+value+"']").attr("selected","selected");
            }
        }
        function queren2(value){
            var result= confirm("系统匹配到与您发货地址更合适的分站是否要切换");
            if( result== true ){
                $("#email option[value='"+value+"']").attr("selected","selected");
            }
        }


        //进入就发送请求
        $.ajax({
            url:"../../getAllSubstation",
            type:"post",
            data:{
            },
            dataType:"json",
            success:function (data) {
                //动态添加下拉框
                for(var i=0;i<data.length;i++){
                    $("#substationUnit").append("<option value='"+data[i].subId +"'>"+data[i].subName + "</option>");
                }
                for(var i=0;i<data.length;i++){
                    $("#email").append("<option value='"+data[i].subId +"'>"+data[i].subName + "</option>");
                }
                //刷新
                form.render('select');
                //将id设置到运单号中
                $("#waybill_id").val(data[0].numeric[0])
                $("#ordernumber").val(data[0].numeric[1])
                // @{}
                /* var zhi=request.getSession().getAttribute("Waybill");
                  alert(zhi);*/
                //通过class循环绑定离开焦点事件
                $('.aggregateamount').blur(function(){
                    //存储总值
                    var a=1;
                    $(".aggregateamount").each(function(){
                        //判断是否为null和kong
                        if($(this).val()!=""&&$(this).val()!=null){
                            a+=parseInt($(this).val());
                        }
                    })
                    $('#aggregateamount').val(parseInt($('#basic').val())+parseInt(a)-1);
                })
                //设置业务员以及操作员
                $.ajax({
                    url:"../../getUserAccount",
                    type:"post",
                    data:{},
                    dataType:"json",
                    success:function (data) {
                        //赋值
                        $('#username').val((data.account));
                        $('#username1').val((data.tmsName));
                    }
                })
            }
        })
        //离开焦点事件（判断id是否存在）
        $("#waybill_id").blur(function(){
            $.ajax({
                url:"../../getWaybillById",
                type:"post",
                data:{
                    id:$("#waybill_id").val()
                },
                dataType:"json",
                success:function (data) {
                    //判断是否为空
                    if (data.waybillId!=null){
                        alert("运单号已存在请更换运单号将自动填充");
                        //设置为uuid
                        $("#waybill_id").val("");
                    }

                }
            })
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            //分站验证
            dizhi();
            //得到发货地址
            var xiangxi=$('#detailedAddress1').val();
            //根据-分割
            //var kl=xiangxi.split("-");
            //新增发货地址
            $.ajax({
                url:"../../insertConsignerTmsRegion",
                type:"post",
                data:{
                    xiangxi:xiangxi
                },
                dataType:"text",
                success:function (data) {
                    //得到收货地址
                    var xiangxi1=$('#detailedAddress').val();
                    //根据-分割
                    //var kl1=xiangxi1.split("-");
                    //新增收货地址
                    $.ajax({
                        url:"../../insertConsigneeTmsRegion",
                        type:"post",
                        data:{
                            xiangxi:xiangxi1
                        },
                        dataType:"text",
                        success:function (data) {
                            //新增收货人
                            $.ajax({
                                url:"../../insertConsignee",
                                type:"post",
                                data:{
                                    forwardingunit: $("#textValue2").val(),
                                    clientname: $("#textValue3").val(),
                                    phone:  $("#phone1").val(),
                                    alternatephone:$("#alternatephone1").val(),
                                    clientgrade:'普通',
                                    remark: $("#detailedAddress").val()
                                },
                                dataType:"text",
                                success:function (data) {
                                    //新增发货人
                                    $.ajax({
                                        url:"../../insertConsigner",
                                        type:"post",
                                        data:{
                                            forwardingunit: $("#textValue0").val(),
                                            clientname: $("#textValue1").val(),
                                            phone:  $("#phone").val(),
                                            alternatephone:$("#alternatephone1").val(),
                                            clientgrade:'普通',
                                            remark: $("#detailedAddress1").val()
                                        },
                                        dataType:"text",
                                        success:function (data) {
                                            //新增发货人
                                            $.ajax({
                                                url:"../../insertFreightinformation",
                                                type:"post",
                                                data:{
                                                    uid:$("#username").val(),
                                                    //承诺日期
                                                    datearrival:$("#date").val(),
                                                    //货物名称
                                                    descriptiongoods:$("#descriptiongoods").val(),
                                                    //包装方式
                                                    packaging:$('#packaging option:selected').text(),
                                                    //货物数量
                                                    quantity:$("#quantity").val(),
                                                    //重量kg
                                                    weight:$("#weight").val(),
                                                    //体积m3立方米
                                                    volume :$("#volume").val(),
                                                    //货物单价
                                                    unitprice:$("#unitprice").val(),
                                                    //收费方式
                                                    tollcollectionmanner: $('#tollcollectionmanner option:selected').text(),
                                                    //提货费
                                                    picupcharge:$("#picupcharge").val(),
                                                    //送货费
                                                    deliveryfee:$("#deliveryfee").val(),
                                                    //货物价值
                                                    cargovalue:$("#cargovalue").val(),
                                                    //保价费用
                                                    premium:$("#premium").val(),
                                                    //卸货费
                                                    unloadfee:$("#unloadfee").val(),
                                                    //其它费用
                                                    elsefee:$("#elsefee").val(),
                                                    //返利代收
                                                    rebate:$("#rebate").val(),
                                                    //应收总金额
                                                    aggregateamount:$("#aggregateamount").val(),
                                                    //付款方式
                                                    paymentmethod:$("#paymentmethod").val(),
                                                    //现收
                                                    nowclosed:$("#nowclosed").val(),
                                                    //到付
                                                    freightcollect:$("#freightcollect").val(),
                                                    //备注
                                                    remark:$("#remark").val(),
                                                    //订单编号
                                                    ordernumber:$("#ordernumber").val(),
                                                    //基本费用
                                                    cost:$('#basic').val()
                                                },
                                                dataType:"text",
                                                success:function (data) {
                                                    $.ajax({
                                                        url:"../../insertWaybill",
                                                        type:"post",
                                                        data:{
                                                            waybillId:$("#waybill_id").val(),
                                                            substationunit:$('#substationUnit option:selected').val(),
                                                            consigndate:$('#date1').val(),
                                                            modetransport:$('#modetransport option:selected').val(),
                                                            typetransportation:$('#typetransportation option:selected').val(),
                                                            arrivalCity:$('#arrivalCity').val(),
                                                        },
                                                        dataType:"text",
                                                        success:function (data) {
                                                            location.href = '/start/index.html#/waybillManagement/waybill/';
                                                        }
                                                    })

                                                }
                                            })
                                        }
                                    })
                                }
                            })
                        }
                    })
                }
            })
            return false;
        });


        //用于存储查询地址
        var selectAll = ['getAllConsignerByClientname', 'getAllConsignerByPhone', 'getAllConsigneeByClientname', 'getAllConsigneeByPhone'];
        //用于得到当前需要增加的下拉列表提示下标
        var indexDate = 0;
        $(".selectTitleDiv").each(function (i, z) {
            //查询需要存放的标签值
            $.ajax({
                url: "../../"+selectAll[i],
                type: 'post',
                success: function (data) {
                    //当前需要增加的下拉列表下标
                    indexDate = data.index;
                    //增加下拉列表提示
                    $(document).ready(function () {
                        //增加下拉列表提示
                        $("#search-form" + data.index).autocomplete({
                            hints: data.data,
                            width: 300,
                            height: 30
                        });
                    });
                }
            })
        })

        //绑定文本框失焦事件 用于隐藏下拉提示
        $('.textValue').blur(function () {
            //增加延时器防止点击的时候隐藏
            setTimeout(function () {
                $(".proposal-box").css("display", "none")
            }, 200);

        })
        //绑定文本框更改事件 用于显示隐藏的下拉提示
        $('.textValue').keyup(function () {
            //alert($('.textValue').index(this));
            $("#search-form" + $('.textValue').index(this) + " .proposal-box").css("display", "block")
        })
        //用于下拉列表提示
        $.fn.autocomplete = function (params) {
            //Selections
            var currentSelection = -1;
            var currentProposals = [];
            //Default parameters
            params = $.extend({
                hints: [],
                placeholder: 'Search',
                width: 200,
                height: 16,
                showButton: true,
                buttonText: 'Search',
                onSubmit: function (text) {
                },
                onBlur: function () {
                }
            }, params);
            var searchContainer = $("#search-form" + indexDate)
            //Text input
            var input = $("#textValue" + indexDate);
            //Proposals
            var proposals = $('<div style=" z-index:999"></div>')
                .addClass('proposal-box')
                .css('width', 186)
                .css('top', 30);
            var proposalList = $('<ul></ul>')
                .addClass('proposal-list');

            proposals.append(proposalList);

            input.keydown(function (e) {
                switch (e.which) {
                    case 38: // Up arrow
                        e.preventDefault();
                        $('ul.proposal-list li').removeClass('selected');
                        if ((currentSelection - 1) >= 0) {
                            currentSelection--;
                            $("ul.proposal-list li:eq(" + currentSelection + ")")
                                .addClass('selected');
                        } else {
                            currentSelection = -1;
                        }
                        break;
                    case 40: // Down arrow
                        e.preventDefault();
                        if ((currentSelection + 1) < currentProposals.length) {
                            $('ul.proposal-list li').removeClass('selected');
                            currentSelection++;
                            $("ul.proposal-list li:eq(" + currentSelection + ")")
                                .addClass('selected');
                        }
                        break;
                    case 13: // Enter
                        if (currentSelection > -1) {
                            var text = $("ul.proposal-list li:eq(" + currentSelection + ")").html();
                            input.val(text);
                        }
                        currentSelection = -1;
                        proposalList.empty();
                        params.onSubmit(input.val());
                        break;
                    case 27: // Esc button
                        currentSelection = -1;
                        proposalList.empty();
                        input.val('');
                        break;
                }
            });
            //keyup事件最后发生，一次键盘敲入事件彻底完成。
            input.bind("keyup", function (e) {
                if (e.which != 13 && e.which != 27
                    && e.which != 38 && e.which != 40) {
                    currentProposals = [];
                    currentSelection = -1;
                    proposalList.empty();
                    if (input.val() != '') {
                        var word = "^" + input.val() + ".*";
                        proposalList.empty();
                        for (var test in params.hints) {
                            if (params.hints[test].match(word)) {
                                currentProposals.push(params.hints[test]);
                                var element = $('<li></li>')
                                    .html(params.hints[test])
                                    .addClass('proposal')
                                    .click(function () {
                                        proposalList.empty();
                                        params.onSubmit(input.val());
                                        //定义一个变量用于区分发货人和收货人;
                                        var url = "../../getAllConsignerByConsignerId";
                                        if (input.attr('id') == 'textValue2' || input.attr('id') == 'textValue3') {
                                            //收货人
                                            url = "../../getAllConsigneeByConsigneeId";
                                        }
                                        //根据id查询到收货人或发货人信息
                                        $.ajax({
                                            url: url,
                                            type: 'post',
                                            data: {
                                                'id': $(this).html().substring($(this).html().indexOf('号') + 1, $(this).html().length - 1)
                                            },
                                            async: false,
                                            success: function (data) {
                                                //判断是收货人还是发货人
                                                if (data.type == '收货人') {
                                                    //收货人单位
                                                    $("#textValue2").val(data.data.forwardingunit);
                                                    //收货人名称
                                                    $("#textValue3").val(data.data.clientname);
                                                    //电话
                                                    $("#phone1").val(data.data.phone);
                                                    //备用电话
                                                    $("#alternatephone1").val(data.data.alternatephone);
                                                    //收货地址
                                                    $("#detailedAddress").val(data.data.remark);
                                                } else {
                                                    //发货人单位
                                                    $("#textValue0").val(data.data.forwardingunit);
                                                    //发货人名称
                                                    $("#textValue1").val(data.data.clientname);
                                                    //电话
                                                    $("#phone").val(data.data.phone);
                                                    //备用电话
                                                    $("#alternatephone").val(data.data.alternatephone);
                                                    //发货地址
                                                    $("#detailedAddress1").val(data.data.remark);
                                                }
                                            }
                                        })
                                    })
                                    .mouseenter(function () {
                                        $(this).addClass('selected');
                                    })
                                    .mouseleave(function () {
                                        $(this).removeClass('selected');
                                    });
                                proposalList.append(element);
                            }
                        }
                    }
                }
            });
            searchContainer.append(proposals);
            //手动渲染
            form.render();
            return false;
        };
    });
</script>






